package router

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"videos/video-api/client"
	"videos/video-api/request"
	"videos/video-rpc/proto/video"
)

func UserRegister(c *gin.Context) {
	var data request.UserRegister
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "未接参数",
			"data": nil,
		})
		return
	}
	register, err := client.UserRegister(c, &video.UserRegisterReq{
		Tel:  data.Tel,
		Code: data.Code,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "注册失败",
			"data": nil,
		})
		return
	}
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "注册成功",
			"data": register,
		})
	}
}

func UserLogin(c *gin.Context) {
	var data request.UserRegister
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "未接参数",
			"data": nil,
		})
		return
	}
	register, err := client.UserLogin(c, &video.UserLoginReq{
		Tel:  data.Tel,
		Code: data.Code,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "注册失败",
			"data": nil,
		})
		return
	}
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "注册成功",
			"data": register,
		})
	}
}

func Update(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "未接收参数",
			"data": nil,
		})
		return
	}
	ext := file.Filename
	if ext != ".mp4" {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "文件格式不正确",
			"data": nil,
		})
		return
	}
	if file.Size > 50*1024*1024 {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "文件内存太大",
			"data": nil,
		})
		return
	}
	Imag := "D:\\GoWork\\zg5\\RK\\videos\\video-api\\image\\images/" + ext
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "文件上传成功",
		"data": Imag,
	})
}

func UserSend(c *gin.Context) {

}

func VideoList(c *gin.Context) {

}

func VideoCreate(c *gin.Context) {

}

func VideoSO(c *gin.Context) {

}

func VideoUpdate(c *gin.Context) {

}

func VideoDel(c *gin.Context) {

}
